<template>
    <div class="withdraw page">
        <formHeader :title="'提现'" color></formHeader>
        <div class="con">
            <div class="bankCard" @click="turn">
                <div class="info" v-if="flag">
                    <div class="card">{{data.bank+'('+data.accName+')'}}</div>
                    <div class="desc">{{data.number}}</div>
                </div>
                <div class="info" v-else>
                    <div class="card">添加银行卡</div>
                    <div class="desc">提现到新增银行卡</div>
                </div>
                <div class="control">
                    <i class="cubeic-arrow"></i>
                </div>
            </div>
            <div class="input">
                <div class="title">提现金额</div>
                <div class="num">
                    <div class="rmb">¥</div>
                    <input v-model="amount" oninput="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" placeholder="输入金额">
                </div>
                <div class="tips">
                    <div class="all" v-if="allMoney">可提现金额{{allMoney}}元</div>
                    <div class="toDraw" @click="allIn()">全部提现</div>
                </div>
            </div>
            <div class="sub" @click="deposit">提现</div>

            <div class="msg">
                1、满100元方可提现，提现申请提交时间为每月10-15日！
                2、提现将在1-2个工作日（非工作日往后延）发放您申请
                的收款账户内，请注意查收！
            </div>
        </div>
    </div>
</template>

<script>
    import formHeader from '@/components/form-header'
    import eventBus from "@/common/js/eventbus";
    import {deposit} from '@/api/account'
    import {showCorrect} from "../../dialog";
    import {showError} from "../../toast";
    export default {
        name: "index",
        components:{formHeader},
        data(){
            return{
                data:{
                    accBranch:null,
                    accName:null,
                    bank:null,
                    number:null
                },
                amount:null,
                flag:false,
                allMoney:0
            }
        },
        methods:{
            turn(){
                this.$router.push({
                    path:'/withdraw/bank'
                })
            },
            allIn(){
                this.amount = this.allMoney
            },
            deposit(){
                if (!this.amount){
                    showError('请输入提现金额')
                    return
                }
                if (this.amount<100){
                    showError('提现金额需100元以上')
                    return
                }
                if (!this.data.accName){
                    showError('请添加开户人')
                    return
                }
                if (!this.data.bank){
                    showError('请添加开户银行')
                    return
                }
                if (!this.data.accBranch){
                    showError('请添加银行分行')
                    return
                }
                if (!this.data.number){
                    showError('请添加银行卡号')
                    return
                }
                let data={
                    amount:this.amount,
                    accName:this.data.accName,
                    bank:this.data.bank,
                    accBranch:this.data.accBranch,
                    number:this.data.number,
                    identify:0
                }
                console.log(data)
                deposit(data).then(res=>{
                    if (res.code==10000){
                        showCorrect('申请成功')
                        this.$router.push({
                            path:'/my'
                        })
                    }
                })
            }
        },
        activated() {
            eventBus.$on('msg',data=>{
                this.data = data
                this.flag = true
            })
            this.allMoney = this.$route.query.amount
        }
    }
</script>

<style scoped lang="stylus">
.withdraw
    background $page-bg
    .con
        margin-top 57px
        .bankCard
            display flex
            padding 12px
            justify-content space-between
            align-items center
            background-color #fff
            border-bottom 1px solid #ccc
            .info
                .card
                    font-size 17px
                    line-height 24px
                    color #333
                .desc
                    font-size 15px
                    color #999
                    line-height 21px
            .control
                color #ccc
                font-size 15px
        .input
             background-color #fff
             padding 12px
            .title
                color  #333
                line-height 24px
                font-size 17px
            .num
                display flex
                align-items center
                margin-top 40px
                .rmb
                    font-size 30px
                    font-weight bold
                    margin-right 6px
                input
                    font-size 30px
                input:focus {
                    outline none
                }
            .tips
                display flex
                margin-top 20px
                justify-content space-between
                font-size 15px
                line-height 21px
                .all
                    color #b6b9bb
                .toDraw
                    color #00d6c0
        .sub
            margin 80px auto
            width 335px
            height 47px
            line-height 47px
            background-color: #00d6c0
            color #fff
            border-radius 5px
            font-size 18px
            text-align center
        .msg
            padding 9px 13px
            background-color: #fff
            font-size 12px
            color #908F93
            border-radius 8px
            width 310px
            margin 0 auto

</style>